require 'overrides'

# Filters added to this controller will be run for all controllers in the application.
# Likewise, all the methods added will be available for all controllers.
class ApplicationController < ActionController::Base
  
  layout "default"
  
  before_filter :session_control, :create_settings
  
  def session_control(expire_after = 1.hour)
    return unless session
    reset_session if session['expiry_time'] && session['expiry_time'] < Time.now
    session['expiry_time'] = Time.now + expire_after
  end
  
  def require_login
    unless session[:user]
      flash[:notice] = "Bitte melden Sie sich zuerst am System an."
      redirect_to(:controller => 'user', :action => 'login')
    end
  end

  def create_settings
    if Setting.count == 0
      s = Setting.new
      s.save
    end
  end
end